#include <iostream>
#include <map>
#include <algorithm> // For max_element
using namespace std;

int main() 
{
    int N;
    cin >> N;
    map<int, int> a;
    for (int i = 0; i < N; ++i) 
	{
        int A, C;
        cin >> A >> C;

        if (a.find(C) != a.end()) 
		{
            a[C] = min(a[C], A);
        } 
		else 
		{
            a[C] = A;
        }
    }

    int ans = 0;
    for (map<int,int>::iterator it=a.begin();it!=a.end();it++) 
	{
        ans = max(ans, it->second);
    }
    cout << ans << endl;
    return 0;
}
